package com.infore.remoteControl.repository;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.infore.remoteControl.entity.protocolEntity.Protocol;

@Repository
public interface IProtocolRepository extends JpaRepository<Protocol, String>, JpaSpecificationExecutor<Protocol> {
	
	// 注意更新和删除是需要加事务的， 并且要加上 @Modify的注解
	// 批量删除
	@Modifying
	@Transactional
	@Query(value="delete from Protocol p where p.protocolId in (:ids) ")
	int deleteBatchByIds(@Param("ids")List<String> ids);
	/** 批量删除 **/
	@Modifying
	@Transactional
	int deleteByProtocolIdIn(List<String> ids);
	/** 分页查询(协议序号排序) **/
	Page<Protocol> findByOrderByNumbers(Pageable pageable);
	/** 按协议序号排序查询 **/
	List<Protocol> findByOrderByNumbers();
	/** 根据协议ID查询 **/
	Protocol findByProtocolId(String prtocolId);
	/** 根据协议名称查询 **/
	List<Protocol> findByName(String name);
	/** 根据协议编号查询 **/
	List<Protocol> findByCode(String code);
	/** 根据协议序号查询 **/
	Protocol findByNumbers(String numbers);
}
